﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MyTest
{
    public class Product2 : IComparable
    {

        private string name;
        private string typeName;
        public string Name { get => name; set => name = value; }
        public Product2()
        {

        }
        public Product2(string name, string typeName)
        {
            this.name = name;
            this.typeName = typeName;
        }

        //重写Equals和GetHashCode
        public override bool Equals(object obj)
        {
            var product = obj as Product2;
            return product != null &&
                   name == product.name &&
                   typeName == product.typeName;
        }

        public override int GetHashCode()
        {
            var hashCode = -1308945084;
            hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(name);
            hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(typeName);
            return hashCode;
        }

        public int CompareTo(object obj)
        {
            return name.CompareTo((obj as Product2).name);
        }
    }
}



